package com.yxq.mdt.app.modules.market.ui;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.orhanobut.hawk.Hawk;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.application.IntentHelper;
import com.yxq.mdt.app.constant.Constant;
import com.yxq.mdt.app.constant.RouteTable;
import com.yxq.mdt.app.constant.SPKey;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.main.bean.NameAndPhoneBean;
import com.yxq.mdt.app.modules.market.bean.MallBannerBean;
import com.yxq.mdt.app.modules.market.bean.MallClassGoodsBean;
import com.yxq.mdt.app.modules.market.bean.MallGoodsBean;
import com.yxq.mdt.app.modules.market.bean.MallGridListBean;
import com.yxq.mdt.app.modules.market.bean.MallListBean;
import com.yxq.mdt.app.modules.market.bean.MallNoticeBean;
import com.yxq.mdt.app.modules.market.bean.MallPMBean;
import com.yxq.mdt.app.modules.market.bean.MallPanicBuyingBean;
import com.yxq.mdt.app.modules.market.bean.MallRecommendBean;
import com.yxq.mdt.app.modules.market.bean.MallResponseBean;
import com.yxq.mdt.app.modules.pm.ui.PmGoodsDetailTabVerticalActivity;
import com.yxq.mdt.app.modules.socialcontact.bean.GivePresentBean;
import com.yxq.mdt.app.modules.webview.ui.MiWebViewActivity;
import com.yxq.mdt.app.utils.GridSpacingItemDecoration;
import com.yxq.mdt.app.widgets.countdown.CustomCountDownView;
import com.yxq.mdt.app.widgets.pagemenulibrary.IndicatorView;
import com.yxq.mdt.app.widgets.pagemenulibrary.PageMenuLayout;
import com.yxq.mdt.app.widgets.pagemenulibrary.holder.AbstractHolder;
import com.yxq.mdt.app.widgets.pagemenulibrary.holder.PageMenuViewHolderCreator;

import java.util.List;

import butterknife.BindView;

/**
 * @author L
 * @time
 * @describe 商城主页适配器
 */
public class MainMallListAdapter extends BaseMultiItemQuickAdapter<MallListBean, BaseViewHolder> {
    MainMallInterface mainMallInterface;
    RecyclerView goodsView;
    MainMallGoodsListAdapter mainMallGoodsListAdapter;

    public void clear() {
        goodsView = null;
    }

    public interface MainMallInterface {
        void onEnd(String time);
    }

    public void setMainMallInterface(MainMallInterface mainMallInterface) {
        this.mainMallInterface = mainMallInterface;
    }

    public MainMallListAdapter(List<MallListBean> data) {
        super(data);
        //顶部banner
        addItemType(MallListBean.MALL_ITEM_TYPE_BANNER, R.layout.layout_item_banner);
        //菜单列表
        addItemType(MallListBean.MALL_ITEM_TYPE_GRID_MENU, R.layout.layout_item_grid_list);
        //通知
        addItemType(MallListBean.MALL_ITEM_TYPE_NOTICE, R.layout.layout_mall_item_live);
        //抢购
        addItemType(MallListBean.MALL_ITEM_TYPE_PANIC_BUYING, R.layout.layout_item_panic_buying);
        //自定义模块样式0 默认样式
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_1, R.layout.layout_style_0_img_count_1);
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_2, R.layout.layout_style_0_img_count_2);
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_3, R.layout.layout_style_0_img_count_3);
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_4, R.layout.layout_style_0_img_count_4);
        //自定义模块样式1
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_1_2, R.layout.layout_style_1_img_count_2);
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_1_3, R.layout.layout_style_1_img_count_3);
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_1_4, R.layout.layout_style_1_img_count_4);
        //自定义模块样式2
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_2_4, R.layout.layout_style_2_img_count_4);
        //推荐商品
        addItemType(MallListBean.MALL_ITEM_TYPE_CLASS, R.layout.layout_item_class_goods_layout);
        //分页商品
        addItemType(MallListBean.MALL_ITEM_TYPE_GOODS, R.layout.layout_item_main_goods_page_layout);
        //分隔符
        addItemType(MallListBean.MALL_ITEM_TYPE_RECOMMEND_INTERVAL, R.layout.layout_item_goods_interval);
        //团长礼包
        addItemType(MallListBean.MALL_ITEM_TYPE_PM, R.layout.layout_item_pm);
    }

    @Override
    protected void convert(BaseViewHolder helper, MallListBean item) {

        switch (item.getItemType()) {

            case MallListBean.MALL_ITEM_TYPE_BANNER://顶部广告
                ConvenientBanner<MallResponseBean.BannerListBean> banner = helper.getView(R.id.banner);
//                banner.setPageIndicator(new int[]{R.drawable.shape_banner_selector_unchecked, R.drawable.shape_banner_selector_checked});
                banner.setPages(new CBViewHolderCreator() {
                    @Override
                    public Holder createHolder(View itemView) {

                        return new ImageHolderView(itemView);
                    }

                    @Override
                    public int getLayoutId() {
                        return R.layout.layout_banner_mall_item;
                    }
                }, ((MallBannerBean) item).getBannerListBean());
                if (!banner.isTurning()) {
                    banner.startTurning();
                }
                break;

            case MallListBean.MALL_ITEM_TYPE_GRID_MENU://顶部菜单
                RecyclerView menuView = helper.getView(R.id.recyclerView);
                menuView.setLayoutManager(new GridLayoutManager(mContext, 5));
                MallGridListBean mallGridListBean = ((MallGridListBean) item);
                MainMallGridMenuListAdapter mallGridMenuListAdapter = new MainMallGridMenuListAdapter(R.layout.layout_item_main_grid_list_layout, mallGridListBean.getNavIconListBeanList());
                menuView.setAdapter(mallGridMenuListAdapter);
                mallGridMenuListAdapter.setOnItemClickListener((adapter, view, position) -> {
                    Bundle bundle = new Bundle();
                    bundle.putString("title", mallGridMenuListAdapter.getItem(position).getName());
                    IntentHelper.aRouterUriWx(mallGridMenuListAdapter.getItem(position).getSkip_state(), mallGridMenuListAdapter.getItem(position).getUrl(), bundle);
                });
                break;

            case MallListBean.MALL_ITEM_TYPE_NOTICE://通知
                MallNoticeBean mallNoticeBean = ((MallNoticeBean) item);
                helper.setText(R.id.main_notice_tv_txt, mallNoticeBean.getNotice());
                TextView tvNotice = helper.getView(R.id.main_notice_tv_txt);
                tvNotice.setSelected(true);
                break;

            case MallListBean.MALL_ITEM_TYPE_PANIC_BUYING://秒杀
                MallPanicBuyingBean mallPanicBuyingBean = ((MallPanicBuyingBean) item);
                CustomCountDownView countdownView = helper.getView(R.id.panic_tv_time);//倒计时
                countdownView.setOnCountdownEndListener(cv -> {
                    if (mainMallInterface != null) {
                        mainMallInterface.onEnd(mallPanicBuyingBean.getMiaoshaBean().getName());
                    }
                });
                countdownView.start(mallPanicBuyingBean.getMiaoshaBean().getRest_time() * 1000);//秒杀倒计时
                helper.setText(R.id.panic_tv_count, mallPanicBuyingBean.getMiaoshaBean().getName());//秒杀场次
                helper.getView(R.id.panic_tv_count).setOnClickListener(view -> {
                    Bundle bundle = new Bundle();
                    IntentHelper.arouterUri(RouteTable.ROUTER_ACTIVITY_SPIKE, bundle);
                });

                //秒杀商品
//                RecyclerView buyView = helper.getView(R.id.recyclerView);
//                buyView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
//                MainMallPanicBuyListAdapter mainMallPanicBuyListAdapter = new MainMallPanicBuyListAdapter(R.layout.layout_item_main_panic_buy_list_layout, mallPanicBuyingBean.getMiaoshaBean().getGoods_list());
//                buyView.setAdapter(mainMallPanicBuyListAdapter);
//                mainMallPanicBuyListAdapter.setOnItemClickListener((adapter, view, position) -> {
//                    Bundle bundle = new Bundle();
//                    bundle.putString("id", mainMallPanicBuyListAdapter.getItem(position).getId() + "");
//                    IntentHelper.arouterUri(RouteTable.ROUTER_ACTIVITY_SPIKE_GOODS_DETAIL, bundle);
//                });
//                if (buyView.getItemDecorationCount() == 0) {
//                    buyView.addItemDecoration(new GridSpacingItemDecoration(3, 15, false));
//                }
//                buyView.setOnTouchListener((view, motionEvent) -> {
//                    if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
//                        IntentHelper.arouterUri(RouteTable.ROUTER_ACTIVITY_SPIKE);
//                        return true;
//                    }
//                    return true;
//                });

                PageMenuLayout<MallResponseBean.MiaoshaBean.GoodsListBean> mPageMenuLayout = helper.getView(R.id.pagemenu);
                IndicatorView entranceIndicatorView = helper.getView(R.id.main_home_entrance_indicator);

                mPageMenuLayout.setPageDatas(mallPanicBuyingBean.getMiaoshaBean().getGoods_list(), new PageMenuViewHolderCreator() {
                    @Override
                    public AbstractHolder createHolder(View itemView) {

                        return new AbstractHolder<MallResponseBean.MiaoshaBean.GoodsListBean>(itemView) {
                            ImageView icon;
                            TextView name;
                            TextView priceView;
                            TextView priceSell;

                            @Override
                            protected void initView(View itemView) {
                                icon = itemView.findViewById(R.id.main_item_iv_grid_icon);
                                name = itemView.findViewById(R.id.main_item_tv_grid_title);
                                priceView = itemView.findViewById(R.id.main_item_tv_grid_price);
                                priceSell = itemView.findViewById(R.id.main_item_tv_grid_sell_price);
                            }

                            @Override
                            public void bindView(RecyclerView.ViewHolder holder, final MallResponseBean.MiaoshaBean.GoodsListBean data, int pos) {

                                GlideHelper.setLoadRoundImage(mContext, data.getPic(), R.color.gray, icon);
                                name.setText(data.getName());
                                priceView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                                priceView.setText(String.format("￥%.2f", data.getPrice()));
                                priceSell.setText((String.format("￥%.2f", data.getMiaosha_price())));
                                itemView.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Bundle bundle = new Bundle();
                                        bundle.putString("id", data.getId() + "");
                                        IntentHelper.arouterUri(RouteTable.ROUTER_ACTIVITY_SPIKE_GOODS_DETAIL, bundle);
                                    }
                                });
                            }

                        };
                    }

                    @Override
                    public int getLayoutId() {
                        return R.layout.layout_item_main_panic_buy_list_layout;
                    }
                });
                entranceIndicatorView.setIndicatorCount(mPageMenuLayout.getPageCount());
                mPageMenuLayout.setOnPageListener(new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        entranceIndicatorView.setCurrentIndicator(position);
                    }
                });
                mPageMenuLayout.setCurrentPage(0);

                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_1://自定义模块样式0 1张图 高度不固定
                MallRecommendBean mallRecommendBean = ((MallRecommendBean) item);
                ImageView img1 = helper.getView(R.id.style_0_img_count_1_iv_img);
                GlideHelper.setLoadImageWarpHeight(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                Bundle bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_2://自定义模块样式0 2张图
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_0_img_count_2_iv_img_0);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                ImageView img2 = helper.getView(R.id.style_0_img_count_2_iv_img_1);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_3://自定义模块样式0 3张图
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_0_img_count_3_iv_img_0);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                img2 = helper.getView(R.id.style_0_img_count_3_iv_img_1);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                ImageView img3 = helper.getView(R.id.style_0_img_count_3_iv_img_2);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getPic_url(), R.color.gray, img3);
                img3.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_0_4://自定义模块样式0 4张图
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_0_img_count_4_iv_img_0);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                img2 = helper.getView(R.id.style_0_img_count_4_iv_img_1);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                img3 = helper.getView(R.id.style_0_img_count_4_iv_img_2);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getPic_url(), R.color.gray, img3);
                img3.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getUrl(), bundle));
                ImageView img4 = helper.getView(R.id.style_0_img_count_4_iv_img_3);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(3).getPic_url(), R.color.gray, img4);
                img4.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(3).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_1_2://自定义模块样式1 2张图
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_1_img_count_2_iv_img_0);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) img1.getLayoutParams();
                params.height = Constant.SPAN_COUNT_2_WIDTH;
                img1.setLayoutParams(params);
                img2 = helper.getView(R.id.style_1_img_count_2_iv_img_1);
                img2.setLayoutParams(params);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_1_3://自定义模块样式1 3张图
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_1_img_count_3_iv_img_0);
                params = (LinearLayout.LayoutParams) img1.getLayoutParams();
                params.height = Constant.SPAN_COUNT_3_WIDTH;
                img1.setLayoutParams(params);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                img2 = helper.getView(R.id.style_1_img_count_3_iv_img_1);
                img2.setLayoutParams(params);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                img3 = helper.getView(R.id.style_1_img_count_3_iv_img_2);
                img3.setLayoutParams(params);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getPic_url(), R.color.gray, img3);
                img3.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_1_4://自定义模块样式1 4张图
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_1_img_count_2_iv_img_0);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                img2 = helper.getView(R.id.style_1_img_count_2_iv_img_1);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                img3 = helper.getView(R.id.style_1_img_count_2_iv_img_2);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getPic_url(), R.color.gray, img3);
                img3.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getUrl(), bundle));
                img4 = helper.getView(R.id.style_1_img_count_2_iv_img_3);
                GlideHelper.setLoadRoundImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(3).getPic_url(), R.color.gray, img4);
                img4.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(3).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_RECOMMEND_STYLE_2_4://自定义模块样式2
                mallRecommendBean = ((MallRecommendBean) item);
                img1 = helper.getView(R.id.style_2_img_count_4_iv_img_0);
                img2 = helper.getView(R.id.style_2_img_count_4_iv_img_1);
                img3 = helper.getView(R.id.style_2_img_count_4_iv_img_2);
                img4 = helper.getView(R.id.style_2_img_count_4_iv_img_3);
                GlideHelper.setLoadImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getPic_url(), R.color.gray, img1);
                GlideHelper.setLoadImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getPic_url(), R.color.gray, img2);
                GlideHelper.setLoadImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getPic_url(), R.color.gray, img3);
                GlideHelper.setLoadImage(mContext, mallRecommendBean.getBlockListBean().getData().getPic_list().get(3).getPic_url(), R.color.gray, img4);
                bundle = new Bundle();
                bundle.putString("title", mallRecommendBean.getBlockListBean().getName());
                img1.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(0).getUrl(), bundle));
                img2.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(1).getUrl(), bundle));
                img3.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(2).getUrl(), bundle));
                img4.setOnClickListener(view -> IntentHelper.arouterUri(mallRecommendBean.getBlockListBean().getData().getPic_list().get(3).getUrl(), bundle));
                break;

            case MallListBean.MALL_ITEM_TYPE_CLASS://推荐商品
                MallClassGoodsBean mallClassGoodsBean = ((MallClassGoodsBean) item);
                bundle = new Bundle();
                bundle.putString("title", mallClassGoodsBean.getCatListBean().getName());
                //标题
                helper.setText(R.id.panic_tv_title, mallClassGoodsBean.getCatListBean().getName());
                //广告
                ImageView adImage = helper.getView(R.id.image);
                if (!"".equals(mallClassGoodsBean.getCatListBean().getAdvert_pic()) && !TextUtils.isEmpty(mallClassGoodsBean.getCatListBean().getAdvert_pic())) {
                    adImage.setVisibility(View.VISIBLE);
                    GlideHelper.setLoadRoundImage(mContext, mallClassGoodsBean.getCatListBean().getAdvert_pic(), R.color.gray, adImage);
                } else {
                    adImage.setVisibility(View.GONE);
                }
                adImage.setOnClickListener(view -> IntentHelper.arouterUri(mallClassGoodsBean.getCatListBean().getAdvert_url(), bundle));
                //更多
                helper.getView(R.id.panic_tv_count).setOnClickListener(view -> IntentHelper.arouterUri(mallClassGoodsBean.getCatListBean().getPage_url(), bundle));
                //列表
                RecyclerView classView = helper.getView(R.id.recyclerView);
                classView.setLayoutManager(new StaggeredGridLayoutManager(mallClassGoodsBean.getCols(), StaggeredGridLayoutManager.VERTICAL));
                MainMallClassGoodsListAdapter mainMallClassGoodsListAdapter = new MainMallClassGoodsListAdapter(R.layout.layout_item_cat_goods_layout, mallClassGoodsBean.getCatListBean().getGoods_list());
                classView.setAdapter(mainMallClassGoodsListAdapter);
                mainMallClassGoodsListAdapter.setOnItemClickListener((adapter, view, position) -> {
                    Bundle bundle1 = new Bundle();
                    bundle1.putString("id", mallClassGoodsBean.getCatListBean().getGoods_list().get(position).getId() + "");
                    IntentHelper.arouter(RouteTable.ROUTER_ACTIVITY_GOODS_DETAIL, bundle1);
                });
                if (classView.getItemDecorationCount() == 0) {
                    classView.addItemDecoration(new GridSpacingItemDecoration(mallClassGoodsBean.getCols(), 15, false));
                }
                break;

            case MallListBean.MALL_ITEM_TYPE_GOODS://分页商品
                MallGoodsBean mallGoodsBean = ((MallGoodsBean) item);
                if (goodsView == null) {
                    goodsView = helper.getView(R.id.recyclerView);
                    StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
                    goodsView.setLayoutManager(staggeredGridLayoutManager);
                    mainMallGoodsListAdapter = new MainMallGoodsListAdapter(R.layout.layout_item_goods_list_layout, mallGoodsBean.getList());
                    goodsView.setAdapter(mainMallGoodsListAdapter);
                    if (goodsView.getItemDecorationCount() == 0) {
                        goodsView.addItemDecoration(new GridSpacingItemDecoration(2, 15, false));
                    }
                } else {
                    mainMallGoodsListAdapter.addData(mallGoodsBean.getList());
                    mainMallGoodsListAdapter.notifyDataSetChanged();
                }
                mainMallGoodsListAdapter.setOnItemClickListener((adapter, view, position) -> {
                    Bundle bundle12 = new Bundle();
                    bundle12.putString("id", mainMallGoodsListAdapter.getData().get(position).getId() + "");
                    IntentHelper.arouter(RouteTable.ROUTER_ACTIVITY_GOODS_DETAIL, bundle12);
                });

                break;

            case MallListBean.MALL_ITEM_TYPE_PM://团长礼包
                MallPMBean mallPMBean = ((MallPMBean) item);
                GlideHelper.setLoadImage(mContext, mallPMBean.getGrift_img_url(), R.color.gray, helper.getView(R.id.market_iv_gift_package));
                GlideHelper.setLoadImage(mContext, mallPMBean.getSmall_gift_img_url(), R.color.gray, helper.getView(R.id.market_btn_pm));
                //大礼包
                helper.getView(R.id.market_iv_gift_package).setOnClickListener(v -> {
                    Intent intent = new Intent(mContext, PmGoodsDetailTabVerticalActivity.class);
                    intent.putExtra("id", mallPMBean.getId());
                    mContext.startActivity(intent);
                });
                //小礼包
                helper.getView(R.id.market_btn_pm).setOnClickListener(v -> {
                    Intent intent = new Intent(mContext, PmGoodsDetailTabVerticalActivity.class);
                    intent.putExtra("id", mallPMBean.getSmall_gift_goods_id());
                    intent.putExtra("goodsType", 1);
                    mContext.startActivity(intent);
                });
                break;
        }
    }

    /**
     * 图片轮转实现
     */
    class ImageHolderView extends Holder<MallResponseBean.BannerListBean> {
        private ImageView imageView;

        public ImageHolderView(View itemView) {
            super(itemView);
        }

        @Override
        protected void initView(View itemView) {
            imageView = itemView.findViewById(R.id.banner_image);
            try {
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void updateUI(MallResponseBean.BannerListBean bean) {
            try {
                GlideHelper.setLoadRoundImage(mContext, bean.getPic_url(), R.color.gray, imageView);
            } catch (Exception e) {
                e.printStackTrace();
            }
            Bundle bundle = new Bundle();
            bundle.putString("title", bean.getTitle());
            NameAndPhoneBean nameAndPhoneBean = Hawk.get(SPKey.SP_KEY_NAME_PHONE_INFO);
            //判断礼包是否显示
            if (nameAndPhoneBean != null && nameAndPhoneBean.getPmSetting() != null) {
                if (nameAndPhoneBean.getSmallBag() != null && bean.getPage_url().contains(nameAndPhoneBean.getSmallBag().getGift_goods_id())) {
                    //小礼包
                    bundle.putInt("goodsType", 1);
                    imageView.setOnClickListener(view -> IntentHelper.aRouterUriWx(bean.getSkip_state(), RouteTable.ROUTER_ACTIVITY_GIFT_PACKAGE_DETAIL + "?id=" + nameAndPhoneBean.getSmallBag().getGift_goods_id(), bundle));
                } else if (nameAndPhoneBean.getPmSetting() != null && bean.getPage_url().contains(nameAndPhoneBean.getPmSetting().getGift_goods_id())) {
                    //大礼包
                    imageView.setOnClickListener(view -> IntentHelper.aRouterUriWx(bean.getSkip_state(), RouteTable.ROUTER_ACTIVITY_GIFT_PACKAGE_DETAIL + "?id=" + nameAndPhoneBean.getPmSetting().getGift_goods_id(), bundle));
                } else {
                    imageView.setOnClickListener(view -> IntentHelper.aRouterUriWx(bean.getSkip_state(), bean.getPage_url(), bundle));
                }
            } else {
                imageView.setOnClickListener(view -> IntentHelper.aRouterUriWx(bean.getSkip_state(), bean.getPage_url(), bundle));
            }
        }
    }
}
